﻿@model IEnumerable<StudentPortal.Models.UserProfile>

@{
    ViewBag.Title = "Người dùng";
	Layout = "~/Views/Shared/_Layout.cshtml";
}

<div class="row-fluid">
	<div class="span12">
<p>
    @Html.ActionLink("Thêm", "Create", new { }, new { @class = "btn green" })
</p>
@(Html.Kendo().Grid<StudentPortal.Models.UserProfile>()
	.Name("UserProfile")
	.Columns(columns =>
	{
			columns.Bound(model => model.UserName);
				columns.Bound(model => model.webpages_Group.GroupName);
                columns.Command(command => { command.Custom("Reset").Click("ResetUser"); command.Custom("Sửa").Click("Edit"); command.Custom("Xóa").Click("Delete"); });
	})
	.Groupable()
    .Filterable()
	.Pageable()
	.Sortable()
	.DataSource(
		dataSource => dataSource.Ajax()
			.Read(read => read.Action("Read", "User"))
	)
)

	</div>
</div>
<script type="text/javascript">
	function Edit(e) {
		e.preventDefault();
		var dataItem = this.dataItem($(e.currentTarget).closest('tr'));
		location.href='@Url.Action("Edit","User")/'+dataItem.UserId;
	}
	function Delete(e) {
		e.preventDefault();
		var dataItem = this.dataItem($(e.currentTarget).closest('tr'));
		location.href = '@Url.Action("Delete","User")/' + dataItem.UserId;
	}
    function ResetUser(e) {
        e.preventDefault();
        var dataItem = this.dataItem($(e.currentTarget).closest('tr'));
        $.ajax({
            url: '@Url.Action("Reset", "User", new { Area= "Admin"})',
            type: 'post',
            data: {
                UserId: dataItem.UserId,
            },
            dataType: 'json',
            success: function (o) {
                alert(o.Message);
            }
        })
    }
</script>
